<script type="text/javascript" src="<?=base_url()?>js/popup.js"></script>
<link href="<?=base_url()?>css/popup.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">

  $j(function() {
	  //CLOSING POPUP	
	//Click out event!
	$j("#background-popup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$j(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
	<? if($this->session->flashdata('error_product_quantity'))
	{
		?>
	centerPopup();
	        loadPopup();
			<?
	}
	?>
    //updateshippingmethod(); // Based on change of country	
  });
  /*
  function updateshippingmethod() {
    var country_id = $j('#country').val();
    $j.ajax({
      url: '<?= base_url() ?>store/updateshippingmethod/',
      type: 'POST',
      data: ({country_id:country_id}),
      success: function(html) {
        $j('#shipping-method').html(html);
        $j('#shippingmethod').val($j('#method').val());
        updateshippingcost();
        gettax();
      }
    })
  } // Get the shipping methods based on country
  function updateshippingcost() {
    var method_id = $j('#method').val();
    var code = $j('#coupon-code').val();
    $j.ajax({
      url: '<?= base_url() ?>store/updateshippingcost/',
      type: 'POST',
      data: ({method_id:method_id,code:code}),
      success: function(html) {
        $j('#shipping-cost').html(html);
      }
    })
  } // Get the shipping cost based on shipping method and subtotal, which is depent on discount
  */
  function gettax() {
    var country_id = $j('#country').val();
    var code = $j('#coupon-code').val();
    $j.ajax({
      url: '<?= base_url() ?>store/gettax/',
      type: 'POST',
      data: ({country_id:country_id,code:code}),
      success: function(html) {			
        $j('#tax').html(html);
        var tax = $j('#taxamount').html();
        gettotalprice();
      }
    })
  } // Calculated based on country and subtotal, which is depent on discount

  function checkcoupon() {
    var code = $j('#coupon-code').val();
    if (code != '') {
      $j.ajax({
        url: '<?= base_url() ?>store/checkcoupon/',
        type: 'POST',
        data: ({code:code}),
        success: function(html) {
          if(html=="Err01") { alert('The coupon code is not valid'); }
          else if(html=="Err02") { alert('The coupon code is not actived'); }
          else if(html=="Err03") { alert('The coupon code has been used its allowed times of used'); }
          else if(html=="Err04") { alert('The coupon was expired'); }
          else 
		  { 
		    $j('#discount-area').html(html);
		    //addcoupon(code); 
			gettotalprice(code);
		  }
        }
      })
    } else {
      alert('Please enter a coupon code');
    }
  } // Check if a coupon is valid, and if so then add the coupon
  function addcoupon(code) {
    //var code = $j('#coupon-code').val();
    $j.ajax({
      url: '<?= base_url() ?>store/addcoupon/',
      type: 'POST',
      data: ({code:code}),
      success: function(html) {			
        gettotalprice();
        //updateshippingcost();	
        //$j('.items-list .list').css('height','240px');
        //$j('#discount-info').html(html);					
      }
    })
  }
  function gettotalprice(code) {
    //var method_id = $j('#method').val();
    //var country_id = $j('#country').val();
    //var code = $j('#coupon-code').val();
    $j.ajax({
      url: '<?= base_url() ?>store/totalprice_trade/',
      type: 'POST',
      data: ({code:code}),
      success: function(html) {
        $j('#totalprice').html(html);
      }
    })
  } // Calculated total based on coupon for discount, country for tax, and shipping method
  /*
  function copyaddress() {
    if($j('#sameaddress:checked').val()) {
      $j('#firstname').val('<?= $customer['firstname'] ?>');
      $j('#lastname').val('<?= $customer['lastname'] ?>');
      $j('#address').val('<?= $customer['address'] ?>');
      $j('#city').val('<?= $customer['city'] ?>');
      $j('#state').val('<?= $customer['state'] ?>');
      $j('#postcode').val('<?= $customer['postcode'] ?>');
	   $j('#phone').val('<?= $customer['phone'] ?>');
	    $j('#email').val('<?= $customer['email'] ?>');
    } 
	else 
	{
      $j('#firstname').val('');
      $j('#lastname').val('');
      $j('#address').val('');
      $j('#city').val('');
      $j('#state').val('');
      $j('#postcode').val('');
	  $j('#phone').val('');
      $j('#email').val('');
    }	
  }
  */
  function order() {
    var valid = true;
	
    /*
    if($j('#address').val() == "") { $j('#address').css('background','#fff3a0'); valid = false; }
    else { $j('#address').css('background','#fff'); }
    if($j('#suburb').val() == "") { $j('#suburb').css('background','#fff3a0'); valid = false; }
    else { $j('#suburb').css('background','#fff'); }
	 if($j('#postcode').val() == "") { $j('#postcode').css('background','#fff3a0'); valid = false; }
    else { $j('#postcode').css('background','#fff'); }
	
	 if($j('#phone').val() == "") { $j('#phone').css('background','#fff3a0'); valid = false; }
    else { $j('#phone').css('background','#fff'); }
    if($j('#email').val() == "") 
	{ 
	$j('#email').css('background','#fff3a0'); 
	valid = false; 
	}
	else
	{
		if(!echeck($j('#email').val()))
		{
			$j('#email').css('background','#fff3a0'); 
	valid = false;
		}
		else
		{
			$j('#email').css('background','#fff');
		}
	}
	*/
		if(!$j('#terms-conditions').is(':checked'))
		{
			alert('Please read and accept to Terms and Conditions');
			valid = false;
		}
	
    if (valid) {
	  <? if($cart == NULL)
	  {
		  ?>
		  alert('Your shopping basket is empty. Please update your shopping basket');
		  return false;
		  <?
	  }
	  ?>
      document.orderForm.submit();
    }
	/*
	else
	{
		alert('Please check the highlighted fields to make sure you have entered the correct data.');
		return false;
	}
	*/
  }
  /*
  function echeck(str) {

                var at = "@"
                var dot = "."
                var lat = str.indexOf(at)
                var lstr = str.length
                var ldot = str.indexOf(dot)
                if (str.indexOf(at) == -1) {
                    alert("Please Enter A Valid E-mail")
                    return false
                }

                if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
                    alert("Please Enter A Valid E-mail")
                    return false
                }

                if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
                    alert("Please Enter A Valid E-mail")
                    return false
                }

                if (str.indexOf(at, (lat + 1)) != -1) {
                    alert("Please Enter A Valid E-mail")
                    return false
                }

                if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
                    alert("Please Enter A Valid E-mail")
                    return false
                }

                if (str.indexOf(dot, (lat + 2)) == -1) {
                    alert("Please Enter A Valid E-mail")
                    return false
                }

                if (str.indexOf(" ") != -1) {
                    alert("Please Enter A Valid E-mail")
                    return false
                }


                return true;
            }
*/

function howto() 
{
	$j('#popup-shopping').show();
			centerPopup();
			loadPopup();
}
function checkredeem() {
    var id = $j('#cust_id').val();
    //alert(id);
    if (id != '') {
      $j.ajax({
        url: '<?= base_url() ?>store/checkredeem/',
        type: 'POST',
        data: ({id:id}),
        success: function(html) {
          if(html=="Err01") { alert('The Redeem is not valid'); }
		  else if(html=="Err02") { alert('The Redeem is not available'); }
          else 
		  { 
		    //alert('you get launch offer');
		    $j('#redeem-area').html(html);
			$j('#gst-area').hide();
		    //addcoupon(code); 
			var code='';
			gettotalprice(code);
		  }
        }
      })
    } else {
      alert('Please enter a coupon code');
    }
} 
</script>
<div id="popup-box">
	<?php 
      if($this->session->flashdata('error_product_quantity')!="")
      { ?>
    <div id="popup-shopping">
    	<? } else { ?>
    		<div id="popup-shopping" style="height:350px ! important;">
    	<? }?>
    	<div class="close"><a href="javascript:disablePopup()"><img src="<?=base_url()?>img/CloseButton-Up.png" alt="Close" /></a></div>
        <div style="clear:both"></div>
        <div style="clear:both;padding-top:54px">
           <div id="content-pop" style="width:400px;margin:0 auto; ">
           		<?php 
           			if($this->session->flashdata('error_product_quantity')!="")
					{
           			echo $this->session->flashdata('error_product_quantity');}
					else {?>
						<p>
						 <p class="sub-header">How To Redeem The Launch Offer</p>
						<br>
						To redeem the launch offer you must have 7 of the same item in your shopping basket. If you have 7 of the same item in your shopping basket and hit the "Redeem Launch Offer" button you will only pay for 6, receiving the 7th item for FREE. 
						<br><br>
						The launch offer can be applied to as many products as are in your basket such as:
						<br><br>
						7 x Mens T-shirt - Black = 1x Mens T-shirt - Black for free<br>
						7x Ladies T-shirt - Red = 1x Ladies T-shirt - Red for free<br>
						<br>
						The launch offer can only be redeemed once per customer.
						</p>
					<?}
           		?>
           </div>
        </div>
        <br/>
    </div>
    
</div>
<div id="background-popup"></div>
<div id="store">
  <p><img src="<?php echo base_url(); ?>img/CheckOutHeader.jpg" alt="Checkout" /></p>
  <div style="margin-top:2px;min-height:400px">
    <form name="orderForm" method="post" action="<?= base_url() ?>store/order_trade">
    <table cellspacing="0" style="width:100%;">
      <tr style="text-align:center">
        <td style="width:235px;background:#e8e8e8;padding:0.5em;text-align:left"><span class="green">Please Review Your Order</span></td>
        <td style="width:44px;background:#DCDCDC;padding:0.5em;"><span class="green">Quantity</span></td>
        <td style="background:#e8e8e8;padding:0.5em;"><span class="green">Options</span></td>
        <td style="text-align:center;background:#DCDCDC;padding:0.5em;"><span class="green">Unit Price</span></td>
        <td style="background:#e8e8e8;padding:0.5em;width:400px;padding-left:18px;"><span class="green"><b>Delivery Details</b></span></td>
      </tr>
      <?php $subtotal = 0; ?>
        <tr>
          <td colspan="4" valign="top">
          
            <?php 
			if($cart != NULL)
			{
			 
             echo '<div style="min-height:340px">';
             
			  foreach ($cart as $item)
			  { $var = json_decode($item['attributes'],true); $thumb = $this->Product_model->thumb_photo($item['product_id']); $product = $this->Product_model->identify($item['product_id']); 
			  
			  		$subtotal += intval($item['quantity']) * floatval($item['price']); 
			  		
			  	?> 
            <div style="border:1px solid #e5e5e5;padding:4px;margin:1px 0;font-size:13px">
            <table cellpadding="0" cellspacing="0" style="width:100%;">
              <tr>
                <td style="width:239px;"><table cellpadding="0" cellspacing="0" border="0"><tr><td><span style="padding:2px"><a href="<?=base_url()?>store/product/<?=$product['id']?>"><img width="39px" height="36px" src="<?=base_url()?>uploads/products/<?=md5('mbb'.$product['id'])?>/thumb4/<?=$thumb['name']?>" /></a></span></td><td><?php echo to_short($product['title'],34); ?></td></tr></table></td>
                <td style="width:59px;text-align:center;"><?php echo $item['quantity']; ?></td>
                <td style="width:75px;text-align:center;font-size:12px"><?php if($var) { foreach($var as $v){ echo '<p>'.$v.'</p>';}}?></td>
                <td style="text-align:center;font-size:16px" class="green">$<?= $item['price'] ?></td>
              </tr>
            </table>
              
              </div>
             <?php 
			  }
				$subtotal1=$subtotal;
			 echo '</div>';
             
			}
			?>
            <?php if($cart != NULL)
			{
				?>
                <div style="border-left:1px solid #e5e5e5;border-right:1px solid #e5e5e5;border-bottom:1px solid #e5e5e5;margin-top:30px;min-height:143px">
                  <div style="background: none repeat scroll 0 0 #E8E8E8;padding:4px 0 4px 16px; "><p class="italic-text">
                  	<? if($tax==1){ ?>
                  	Price is inclusive of Tax and Shipping
                  	<? } else {?> Price is exclusive of Tax and inclusive of Shipping<? }?>
                  	</p></div>
                  <div style="background: none repeat scroll 0 0 #E8E8E8;padding:4px 0 4px 16px; margin-top:4px;">
                  	<table width="100%">
                  		<tr>
                  			<td>
                  	<p>
                  	 Choose 7 of the same item and only pay for 6<br>
                  	<a onclick="javascript:howto()" style="color:#f48222; text-decoration: underline; cursor: pointer;">How to redeem your launch offer</a>
                  	 
                  	</p>
                  	</td>
                  	<td align="right">
                  		<div style="float:right; margin-right: 2px;">
                  		<a onclick="checkredeem()" style="cursor: pointer;"><img src="<?=base_url()?>img/RedeemButton.jpg" alt="Redeem" />
                  			<input type="hidden" name="cust_id" id="cust_id" value="<?= $customer['id'] ?>"/>
                  		</div>
                  	</td>
                  	</tr>
                  	</table>
                  </div>
                  	
                  	
                   <div style="margin-top:4px;background: none repeat scroll 0 0 #E8E8E8;padding:4px 4px 0 16px;font-size:13px;height:36px;clear:both;width:446px">
                      <div style="float:left;width:160px"><p style="padding-top:6px">Coupon and discount code</p></div>
                      <div style="float:right;width:206px"><table cellpadding="0" cellspacing="0" border="0">
                   <tr><td><input type="text" name="coupon-code" id="coupon-code" /></td><td><a href="#" onclick="checkcoupon()"><img src="<?=base_url()?>img/update-button.png" alt="Update" /></a></td>
                   </tr>
                  </table>
                      </div>
                   </div>
                   <div id="discount-area" style="padding:8px 8px 8px 16px;"></div>
                   <div id="gst-area" >
                    <div style="margin-top:4px;background: none repeat scroll 0 0 #E8E8E8;padding:4px 4px 0 16px;font-size:13px;height:36px;clear:both;width:446px">
                      <div style="float:left;width:260px"><p style="padding-top:6px">GST</p></div>
                      <div style="float:right;width:55px"><table cellpadding="0" cellspacing="0" border="0">
                   <tr><td align="right" class="green" style="font-size:16px">
                   	<? //if ($tax==1){ echo "$"; printf('%01.2f', round($subtotal1/11),2,PHP_ROUND_HALF_UP);} else { echo "$"; printf('%01.2f', $subtotal/10);} ?>
                   	<? if ($tax==1){$gst=$subtotal/10;  echo "$"; printf('%01.2f', $subtotal/10);} else { echo "$"; printf('%01.2f', $subtotal/10); $gst=0;} ?>
                   </td>
                   </tr>
                  </table>
                      </div>
                   </div>
                   </div>
                   <div id="redeem-area" style="margin-top:4px;padding:8px 8px 8px 16px;"></div>
                </div>
                
                <?
			}
				?>
          </td>
          <td valign="top">
           <div class="delivery" style="padding-left:22px;padding-top:10px;">
             <p class="italic-text" style="margin-bottom:6px;">
             	
             	Delivery lead times are subject to store location.
				<br>
				Orders should be received in to store within 3 to 5 days of order placement.
				<!--Estimate delivery times are within 7 days from order confirmation-->
             	<!--Products ship within 7 days from the time of order. A receipt email will be supplied to you. An invoice will be issued for your purchase via head office-->
             </p>
             <!--
             <hr style="background:#c7c7c7;height:1px;border:none;" /><br />
             <p>Same as my member profile address<span style="float:right;padding-right:2px"><input type="checkbox" id="sameaddress" onchange="copyaddress()" /></span></p><div style="clear:both"></div>
             <p class="italic-text">* Denotes Required Field</p>
             <br />-->
             <hr style="background:#c7c7c7;height:1px;border:none;" /><br />
            
            <table width="402" cellpadding="0" cellspacing="0" border="0">
              <tr height="38">
                <td width="114">Address *</td><td><input type="text" style="width:280px;border:1px solid #e5e5e5;" name="address" id="address" readonly="readonly" value="<?= $customer['address'] ?>" /></td>
              </tr>
              <tr height="38">
                <td>Suburb *</td><td><input type="text" style="width:280px;border:1px solid #e5e5e5;" name="suburb" id="suburb" readonly="readonly" value="<?= $customer['suburb'] ?>"/></td>
              </tr>
               <tr height="38">
                <td>Postcode *</td><td><input type="text" style="width:280px;border:1px solid #e5e5e5;" name="postcode" id="postcode" readonly="readonly" value="<?= $customer['postcode'] ?>"/></td>
              </tr>
              <tr height="38">
                <td>State</td><td>
                	
                	<input type="text" style="width:280px;border:1px solid #e5e5e5;" name="state" id="state" readonly="readonly" value="<?= $customer['state'] ?>"/>
                	<!--
                	<select name="state" style="width:292px" readonly="readonly" /><option value="Victoria" <?php if($customer['state'] == 'Victoria') { echo "selected='selected'";}?>>Victoria</option><option <?php if($customer['state'] == 'New South Wales') { echo "selected='selected'";}?> value="New South Wales">New South Wales</option>
                	<option value="Australian Capital Territory" <?php if($customer['state'] == 'Australian Capital Territory') { echo "selected='selected'";}?>>Australian Capital Territory</option><option value="Queensland" <?php if($customer['state'] == 'Queensland') { echo "selected='selected'";}?>>Queensland</option><option <?php if($customer['state'] == 'Northern Territory') { echo "selected='selected'";}?> value="Northern Territory">Northern Territory</option><option <?php if($customer['state'] == 'South Australia') { echo "selected='selected'";}?> value="South Australia">South Australia</option><option <?php if($customer['state'] == 'Western Australia') { echo "selected='selected'";}?> value="Western Australia">Western Australia</option><option value="Tasmania" <?php if($customer['state'] == 'Tasmania') { echo "selected='selected'";}?>>Tasmania</option></select>
                	-->
                </td>
              </tr>
              <tr>
                <td>Message</td><td><textarea  rows="4" style="color: #666; font-family:Arial, Helvetica, sans-serif; font-size:12px; width:290px;border:1px solid #e5e5e5;" name="msg" id="msg" /></textarea></td>
              </tr>
              
            </table>
            <div style="margin-top:5px;clear:both"><input type="checkbox" name="terms-conditions" id="terms-conditions" />&nbsp;&nbsp;I have read and accept to <a href="<?=base_url()?>terms-and-conditions" target="_blank">Terms and Conditions</a></div>
           </div>
           
          </td>
        </tr>
        <tr><td colspan="4"></td><td></td></tr>
    </table>
    <table cellpadding="0" cellspacing="0" border="0" width="892">
        <tr>
          <td width="458">
          
           <div style="padding:0.3em;border:1px solid #e5e5e5;margin-top:6px;height:56px;width:458px;">
              <div style="float:right;width:169px;background:url(<?=base_url()?>img/greenBG.jpg) no-repeat"><div style="line-height:2em;text-align:center;color:#fff;font-size:2.3em;">$ <span id="totalprice">
              	<?php 
				if($tax==1)
				{	
					$subtotal=$subtotal1+$gst;					
					printf('%01.2f', $subtotal);
				} 
				else{
				printf('%01.2f', $subtotal);} ?></span></div></div>
              <div class="green" style="font-size:22px;margin-top:6px"><p>Total Price</p><p  style="font-size:13px;">Prices Listed are Inc GST</p></div>
            </div>
          </td>
          <td width="434"><div style="text-align:right;height:56px;padding:0.3em;border:1px solid #e5e5e5;width:394px;margin-left:22px;margin-top:6px"><div style="float:right"><img onclick="order()" src="<?php echo base_url(); ?>img/BuyNowButton.jpg"  /></div></div></td>
        </tr>
   </table>
 </form>
 </div>
</div>